<template>
  <div>
    <p class="title">推荐歌单</p>
    <div>
     <van-row gutter="9">
     <van-col span="8" v-for="(item, index) in recommendMusicList" :key="item.id" @click="$router.push({path:'/songsheet',query:{id:item.id,index:index}})">
       <van-image
       @click="random"
        width="100%"
        height="3rem"
        :src="item.picUrl" />
        <p class="song_name">{{item.name}}</p>
     </van-col>
     </van-row>
    </div>
    <p class="title">最新音乐</p>
    <Song v-for="item in hotMusicLIst" :key="item.id"
    :name="item.name"
    :author="item.song.artists[0].name"
    :id="item.id"
    >
    </Song>
  </div>
</template>

<script>
import { recommendMusicAPI, hotMusicAPI } from '@/api'
import Song from '@/components/SongComponents.vue'
export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: 'Home',
  data () {
    return {
      recommendMusicList: [],
      hotMusicLIst: []
    }
  },
  methods: {
    random () {
      this.$store.commit('getRandom')
    }
  },
  async created () {
    const res = await recommendMusicAPI({ limit: 6 })
    this.recommendMusicList = res.data.result
    const songRes = await hotMusicAPI({ limit: 20 })
    this.hotMusicLIst = songRes.data.result
    console.log(this.hotMusicLIst)
  },
  components: {
    Song
  }
}
</script>

<style scoped lang="less">

.title{
  padding: 0.266667rem 0.24rem;
  margin: 0 0 0.24rem 0;
  background-color: #eee;
  color: #333;
  font-size: 15px;
}
.song_name {
  font-size: 0.346667rem;
  padding: 0 0.08rem;
  margin-bottom: 0.266667rem;
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
  -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
  -webkit-line-clamp: 2; /** 显示的行数 **/
  overflow: hidden; /** 隐藏超出的内容 **/
}

</style>
